<template>
  <div>
    <div class="my-body">
      <div class="ipt_a">
        <div style="float: left; line-height: 30px"  class="tab_font-size">样品申请编号：</div>
        <el-input
          v-model="input"
          placeholder="请输入内容"
          style="width: 130px; height: 50px; float: left"
        ></el-input>
      </div>
      <div class="ipt_a">
        <div style="float: left; line-height: 30px"  class="tab_font-size">样品申请编号：</div>
        <el-select v-model="value" placeholder="请选择授权状态"  style="width: 130px; ">
          <el-option label="全部" value="beijing"></el-option>
          <el-option label="审核中" value="shanghai"></el-option>
          <el-option label="申请驳回" value="beijing"></el-option>
          <el-option label="审核通过" value="shanghai"></el-option>
        </el-select>
      </div>
      <div class="ipt_a">
        <div style="float: left; line-height: 30px"  class="tab_font-size">申请医院地区：</div>
        <el-input
          v-model="input"
          placeholder="请输入内容"
          style="width: 130px; height: 50px; float: left"
        ></el-input>
      </div>
      <div class="ipt_a">
        <div style="float: left; line-height: 30px"  class="tab_font-size">经销商：</div>
        <el-input
          v-model="input"
          placeholder="请输入内容"
          style="width: 130px; height: 50px; float: left"
        ></el-input>
      </div>

      
        <el-button type="primary" plain>查询</el-button>
        <el-button>清空</el-button>

        <div style="margin-top: 30px">
          <div>
            <el-button type="primary" @click="sqarea = true" plain>申请</el-button>

            <el-button type="danger" plain>删除</el-button>
          </div>
          <el-dialog
            title="关联企业列表"
            :visible.sync="areaglqylb"
            width="50%"
            :before-close="handleClose"
          >
            <div style="width: 100%">
              <div class="ipt_a">
                <div style="float: left; line-height: 30px">企业编号：</div>
                <el-input
                  v-model="input"
                  placeholder="请输入内容"
                  style="width: 150px; height: 50px; float: left"
                ></el-input>
              </div>

              <div class="ipt_a">
                <div style="float: left; line-height: 30px">企业名称：</div>
                <el-input
                  v-model="input"
                  placeholder="请输入内容"
                  style="width: 150px; height: 50px; float: left"
                ></el-input>
              </div>
              <el-button type="primary">查询</el-button>
              <template>
                <el-table
                  :data="qiyelist"
                  border
                  style="width: 100%; margin-top: 30px"
                 :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
                  ref="singleTable"
                  highlight-current-row
                  @current-change="handleCurrentChangelist"
                >
                  <el-table-column fixed prop="company_code" label="企业编号">
                  </el-table-column>
                  <el-table-column prop="name" label="企业名称">
                  </el-table-column>

                  <!-- <el-table-column prop="province" label="授权产品类型">
								</el-table-column>
								<el-table-column prop="address" label="组织代码">
								</el-table-column>
								<el-table-column prop="address" label="税号">
								</el-table-column> -->
                </el-table>
                <el-pagination
                  @size-change="handleSizeChangea"
                  @current-change="handleCurrentChangea"
                  :current-page="currentPages"
                  :page-sizes="[100, 200, 300, 400]"
                  :page-size="100"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="qiyelisttotal"
                >
                </el-pagination>
              </template>
            </div>
          </el-dialog>
          <el-dialog
            title="申请"
            :visible.sync="sqarea"
            width="50%"
            :before-close="handleClose"
          >
            <div style="width: 100%">
              <el-form ref="form" :model="form" label-width="150px">
                <!-- <el-form-item label="申请编号">
                  <el-input v-model="form.name" style="width: 200px"></el-input>
                  <el-button type="primary">刷新</el-button>
                </el-form-item> -->
                <el-form-item label="样品申请时间">
                  <el-date-picker
                    v-model="value2"
                    type="date"
                    placeholder="选择日期"
                  >
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="经销商">
                  <el-input v-model="form.company_code" style="width: 100px"></el-input>
                <el-input v-model="form.name" style="width: 200px"></el-input>
                <el-button type="primary" @click="areaglqylb = true">...</el-button>
                </el-form-item>
                <el-form-item label="医院\地区">
                  <el-input
                  v-model="form.yiyiancode"
                  style="width: 100px"
                ></el-input>
                <el-input
                  v-model="form.yiyianname"
                  style="width: 200px"
                ></el-input>
                <el-button type="primary" @click="dialogVisiblea = true"
                  >...</el-button
                >
                </el-form-item>
                <el-form-item label="">
                  <el-button type="primary" @click="areatinajia = true"
                    >添加</el-button
                  >
                  <el-button>删除</el-button>
                  <el-button>清空</el-button>
                </el-form-item>
                <el-table :data="tableData" style="width: 100%">
                  <el-table-column type="selection" width="55">
                  </el-table-column>
                  <el-table-column
                    fixed
                    prop="bianhao"
                    label="系列"
                    width="150"
                  >
                  </el-table-column>
                  <el-table-column label="类型" width="150"> </el-table-column>
                  <el-table-column label="规格" width="150"> </el-table-column>
                  <el-table-column label="出货数量" width="150">
                  </el-table-column>
                </el-table>
                <el-form-item> 出库合计数量：0 件 </el-form-item>

                <el-form-item label="原因">
                  <el-input type="textarea" v-model="form.desc"></el-input>
                </el-form-item>

                <el-form-item>
                  <el-button type="primary" @click="onSubmit">提交</el-button>
                  <el-button>取消</el-button>
                </el-form-item>
              </el-form>
            </div>
          </el-dialog>
          <el-dialog
          title="添加地区"
          :visible.sync="dialogVisiblea"
          width="10%"
          :before-close="handleClose"
        >
          <div style="width: 100%">
            <el-button type="primary" @click="hospitalyiyuan(1)">医院</el-button>
            <el-button type="primary" @click="hospitalyiyuan(2)">地区</el-button>
          </div>
        </el-dialog>
        <el-dialog
          title="地区选择"
          :visible.sync="area"
          width="30%"
          :before-close="handleClose"
        >
          <div style="width: 100%">
            <div>
              <el-tree :data="tableDatadq" :props="defaultPropsdq" @node-click="handClickdq"></el-tree>
            </div>
            <div style="margin-top: 30px">
              <el-button type="primary ">放弃返回</el-button>
              <el-button type="primary">确定提交</el-button>
            </div>
          </div>
        </el-dialog>

        <el-dialog
          title="医院科室查询"
          :visible.sync="hospital"
          width="40%"
          :before-close="handleClose"
        >
          <div style="width: 100%">
            <div class="ipt_a">
              <div style="float: left; line-height: 30px">医院编号：</div>
              <el-input
                v-model="input"
                placeholder="请输入内容"
                style="width: 150px; height: 50px; float: left"
              ></el-input>
            </div>
            <div class="ipt_a">
              <div style="float: left; line-height: 30px">医院名称：</div>
              <el-input
                v-model="input"
                placeholder="请输入内容"
                style="width: 150px; height: 50px; float: left"
              ></el-input>
            </div>
            <div class="ipt_a">
              <el-button type="primary">查询</el-button>
            </div>

            <el-table
              :data="tableDatayyks"
              border
              style="width: 100%"
              fit
              size="medium"
             :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
              ref="singleTable"
              highlight-current-row
              @current-change="handleCurrentChange"
            >
              <el-table-column type="selection" width="55"> </el-table-column>
              <el-table-column
                fixed
                prop="hospital_code"
                label="医院编号"
                width="150"
              >
              </el-table-column>
              <el-table-column prop="hospital_name" label="医院名称">
              </el-table-column>
              <el-table-column prop="enddate" label="科室名称">
              </el-table-column>
              <el-table-column prop="address_province" label="省份">
              </el-table-column>
              <el-table-column prop="address" label="地址"> </el-table-column>
            </el-table>
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5, 10]"
              :page-size="pageSize"
              :total="tableDatayyks"
              layout="total, sizes, prev, pager, next, jumper"
            >
            </el-pagination>
          </div>
        </el-dialog>
          <el-dialog
            title="产品规格明细"
            :visible.sync="areatinajia"
            width="50%"
            :before-close="handleClose"
          >
            <div style="width: 100%; height: 500px">
              <div style="width: 30%; float: left">
                <el-tree
                  :data="datacpglist"
                  :props="defaultProps"
                  @node-click="handleNodeClick"
                ></el-tree>
              </div>
              <div style="width: 70%; float: left">
                <template>
                  <el-table :data="guiguilist" border style="width: 100%">
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                    <el-table-column prop="specification_number" label="产品规格">
                    </el-table-column>
                    <el-table-column prop="bianhao" label="产品单价">
                    </el-table-column>
                    <el-table-column prop="bianhao" label="产品数量">
                      <template slot-scope="scope">
                      <el-input
                        style="width: 100px"
                        v-model="scope.row.num"
                        size="small"
                      ></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column prop="remark" label="备注">
                      <template slot-scope="scope">
                      <el-input
                        style="width: 100px"
                        v-model="scope.row.remark"
                        size="small"
                      ></el-input>
                      </template>
                    </el-table-column>
                  </el-table>
                </template>
              </div>
            </div>
            <div>
              <el-button type="primary" @click="onSubmit">提交</el-button>
              <el-button>取消</el-button>
            </div>
          </el-dialog>
          <template>
            <el-table
              :data="tableData"
              border
              style="width: 100%; margin-top: 30px"
             :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
            >
              <el-table-column fixed prop="yp_code" label="申请编号">
              </el-table-column>
              <el-table-column fixed prop="approval_type_txt" label="类型">
              </el-table-column>
              <el-table-column prop="create_time" label="申请日期">
              </el-table-column>
              <el-table-column prop="status_txt" label="申请状态">
              </el-table-column>
              <el-table-column prop="hospital_area_name" label="医院或地区">
              </el-table-column>
              <el-table-column prop="company_name" label="经销商名称">
              </el-table-column>

              <el-table-column fixed="right" label="操作日志">
                <template slot-scope="scope">
                  <!-- <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button> -->
                  <el-button
                    size="mini"
                    @click="handleEdit(scope.$index, scope.row)"
                    >审核日志</el-button
                  >
                </template>
              </el-table-column>

              <el-table-column prop="remark" label="备注" width="200">
              </el-table-column>
            </el-table>
          </template>
		  <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
								:current-page="currentPage" :page-sizes="[5, 10]" :page-size="pageSize"
								:total="tableData.length" layout="total, sizes, prev, pager, next, jumper">
							</el-pagination>
        </div>
        
     
    </div>
    <div class="my-body">
		<div>
          <div style="margin-top: 20px">
            <div class="ipt_a">
              <div style="float: left; line-height: 30px"  class="tab_font-size">积分状态：</div>
              <el-select v-model="value" placeholder="请选择授权状态" style="width: 130px;">
                <el-option label="全部" value="beijing"></el-option>
                <el-option label="审核中" value="shanghai"></el-option>
                <el-option label="申请驳回" value="beijing"></el-option>
                <el-option label="审核通过" value="shanghai"></el-option>
              </el-select>
            </div>
            <div class="ipt_a">
              <div style="float: left; line-height: 30px"  class="tab_font-size">申领年份：</div>
              <div class="block">
                <el-date-picker
                  v-model="value1"
                  type="date"
                  placeholder="选择日期"
                  style="width: 130px;"
                >
                </el-date-picker>
              </div>
            </div>
            <div class="ipt_a">
              <div style="float: left; line-height: 30px"  class="tab_font-size">医院地区：</div>
              <el-input
                v-model="input"
                placeholder="请输入内容"
                style="width: 150px; height: 50px; float: left"
              ></el-input>
            </div>
            <div class="ipt_a">
              <div style="float: left; line-height: 30px"  class="tab_font-size">经销商：</div>
              <el-input
                v-model="input"
                placeholder="请输入内容"
                style="width: 150px; height: 50px; float: left"
              ></el-input>
            </div>
            <el-button type="primary" plain>查询</el-button>
            <el-button>清空</el-button>
          </div>
        </div>
      <div style="margin-top: 30px">
        <div>
          <el-button type="primary" @click="tjjfsq = true" plain>添加</el-button>
          <el-button type="primary" plain>清空</el-button>
          <el-button type="danger" plain>删除</el-button>
          经销商【】当前订货申请信息:订货申请编号【】类型【】订货地区【】
        </div>
        <el-dialog
          title="申请积分申领"
          :visible.sync="tjjfsq"
          width="50%"
          :before-close="handleClose"
        >
          <div style="width: 100%">
            <el-form ref="form" :model="form" label-width="150px">
              <el-form-item label="积分申领编号">
                <el-input v-model="form.name" style="width: 200px"></el-input>
                <el-button type="primary">刷新</el-button>
              </el-form-item>
              <el-form-item label="积分申领类型">
                <el-select v-model="form.region" placeholder="请选择活动区域">
                  <el-option label="一次性积分" value="shanghai"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="经销商">
                <el-input v-model="form.name" style="width: 50px"></el-input>

                <el-input v-model="form.name" style="width: 200px"></el-input>
                <el-button type="primary">...</el-button>
              </el-form-item>
              <el-form-item label="有效授权编号">
                <template>
                  <el-table
                    :data="tableData"
                    border
                    style="width: 100%; margin-top: 30px"
                    :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
                  >
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                    <el-table-column
                      fixed
                      prop="bianhao"
                      label="有效授权编号"
                      width="150"
                    >
                    </el-table-column>
                    <el-table-column
                      fixed
                      prop="bianhao"
                      label="授权医院或地区"
                      width="150"
                    >
                    </el-table-column>
                  </el-table>
                </template>
              </el-form-item>

              <el-form-item label="申领积分">
                <el-input v-model="form.desc"></el-input>
              </el-form-item>
              <el-form-item label="备注">
                <el-input type="textarea" v-model="form.desc"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">申请</el-button>
                <el-button>取消</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-dialog>
        <template>
          <el-table
            :data="tableData"
            border
            style="width: 100%; margin-top: 30px"
           :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
          >
            <el-table-column fixed prop="bianhao" label="申请编号">
            </el-table-column>
            <el-table-column fixed prop="bianhao" label="产品系列">
            </el-table-column>
            <el-table-column prop="senddate" label="产品类型">
            </el-table-column>
            <el-table-column prop="enddate" label="产品规格"> </el-table-column>
            <el-table-column prop="name" label="订货数量"> </el-table-column>
          </el-table>
        </template>
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
								:current-page="currentPage" :page-sizes="[5, 10]" :page-size="pageSize"
								:total="tableData.length" layout="total, sizes, prev, pager, next, jumper">
							</el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { getData, postData } from "@/utils/request.js";
export default {
  data() {
    return {
      area: false,
      sqarea:false,
      tjjfsq: false,
      tablisty: false,
      tablistya: false,
      tablistyb: false,
      areatinajia: false,
      areaglqylb:false,
      dialogVisible: false,
      dialogVisiblea: false,
      hospital:false,
      tableDatayyks: [],
      key: 1, // 为了能每次切换权限的时候重新初始化指令
      options: [
        {
          value: "1",
          label: "全部",
        },
        {
          value: "2",
          label: "一般订单",
        },
        {
          value: "3",
          label: "积分订单",
        },
        {
          value: "3",
          label: "样品订单",
        },
        {
          value: "3",
          label: "换货订单",
        },
      ],
      value1: "",
      value2: "",
      value3: "",
      form: {
        name: "",
        company_id:"",
        company_code:"",
        type: "",
        hospital_id: "",
        area_id: "",
        fp_address: "",
        ht_address: "",
        sh_address: "",
        fp_addressname: "",
        ht_addressname: "",
        sh_addressname: "",
        total_num: "",
        total_price: "",
        use_points: "0",
        remark: "",
        region: "",
        product: "",
        company_code: "",
        area_code: "",
        approval_type: "",
        com_id: "",
        hospitalname: "",
        hospital_code: "",
        yiyianname:"",
        yiyiancode:"",
      },
      radio: "授权医院",
      value: "",
      tableData: [
        {
          bianhao: "PS074107742412L",
          senddate: "2024-05-02",
          enddate: "2024-12-31",
          name: "左心耳",
          province: "完成授权",
          city: "普陀区",
          address: "苏州市中心医院",
          shouqfang: "鹰潭市方园医药有限公司",
          jingxiaos: "鹰潭市方园医药有限公司",
          peisonf: "鹰潭市方园医药有限公司",
          shouqyy: "入院",
          shangcaizhibiao: 3,
        },
      ],
      data: [
        {
          label: "一级 1",
          children: [
            {
              label: "二级 1-1",
            },
          ],
        },
        {
          label: "一级 2",
          children: [
            {
              label: "二级 2-1",
            },
            {
              label: "二级 2-2",
            },
          ],
        },
        {
          label: "一级 3",
          children: [
            {
              label: "二级 3-1",
            },
            {
              label: "二级 3-2",
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "name",
      },
      defaultPropsdq: {
        children: "children",
        label: "label",
      },
      checkAll: false,
      checkedCities: [],
      cities: ["上海", "北京", "广州", "深圳"],
      isIndeterminate: true,
      qiyelist:[],
      qiyelisttotal:"",
      currentPages:1,
      currentPagesa:1,
      pageSizesa:100,
      currentPage:1,
      pageSize:100,
      input:"",
      tableDatadq:[],
      datacpglist:[],
      guiguilist:[],
    };
  },
  created(){
     this.list()
     this.listtab()
     this.getHospital()
     this.indexlistcpxl()
  },
  methods: {
    //产品明细
     indexlistcpxl(){
     
      var data = {
        
        token: localStorage.getItem("token"),
      };
      postData("product.type/indexlist", data).then((res) => {
        // 处理响应数据
        this.datacpglist = res.data
        console.log(res)
      });
     },
    handleNodeClick(val){
      console.log(val)
      var data = {
        product_type_id:val.id,
        token: localStorage.getItem("token"),
      };
      postData("product.Specifications/indexlist", data).then((res) => {
        // 处理响应数据
        this.guiguilist = res.data.data
        console.log(res)
      });
    },
    handClickdq(data){
     
     this.form.yiyiancode =data.dms_city_code
    this.form.yiyianname =data.area_name
    this.form.area_code =data.dms_city_code
    this.form.area_id = data.area_id
    this.area = false;
    this.dialogVisiblea = false;
    this.hospital = false;
   },
     //获取医院列表

     getHospital() {
      var data = {
        // company_id: localStorage.getItem("company_id"),
        token: localStorage.getItem("token"),
      };
      postData("hospital/indexlist", data).then((res) => {
        // 处理响应数据
        if (res.code == 0) {
          console.log(res);
          if(res.data.data == ""){

          }else{
            this.tableDatayyks = res.data.data;
          }
        
        } else {
        }
      });
    },

    //医院列表单选
    handleCurrentChange(val) {
      console.log(val, 66666666666666666666666);
     
      this.currentRow = val;
      this.form.hospitalname = val.hospital_name;
      this.form.hospital_code = val.hospital_code;
      this.form.yiyianname = val.hospital_name;
      this.form.yiyiancode = val.hospital_code;
      this.form.hospital_id = val.id;
      this.dialogVisiblea = false;
      this.hospital = false;
      this.cpindexlist();
    },
    //医院或地区
    hospitalyiyuan(e) {
      this.form.type = e;
      if(e == 1){
      this.hospital = true;
      this.form.area_id = ''
      this.setCurrent()
     
      }else{
        this.area = true
        this.form.hospital_id = ''
        this.qiyelistdq()
      }
      console.log(this.form.type)
     
    },
    setCurrent(row) {
        this.$refs.singleTable.setCurrentRow(row);
      },
     //获取企业签合同的地区列表
     qiyelistdq() {
      var data = {
        company_id: localStorage.getItem("company_id"),
        token: localStorage.getItem("token"),
      };
      postData("company.contract/getArea", data).then((res) => {
        // 处理响应数据
        if (res.code == 0) {
          console.log(res);
          this.tableDatadq = res.data.data
        } else {
        }
      });
    },
     //  企业列表单选
     handleCurrentChangelist(val) {
      this.areaglqylb = false;
      console.log(val);
      this.form.company_id = val.id;
      this.form.company_code = val.company_code;
      this.form.name = val.name;
      this.listtabsqyy(val.id);
    },
    // 企业列表
    listtab() {
      var data = {
        page: this.currentPagesa,
        limit: this.pageSizesa,
        token: localStorage.getItem("token"),
      };
      postData("company/indexList", data).then((res) => {
        this.qiyelist = res.data.data;
        this.qiyelisttotal = res.data.total;
      });
    },
    handleSizeChange(){

    },
    handleClose(){
     this.areaglqylb = false
     this.sqarea = false
     this.dialogVisiblea = false
     this.tjjfsq = false
     this.area = false
     this.areatinajia = false
     this.hospital = false
    },
     //企业列表分页
     handleSizeChangea(val) {
      console.log(`每页 ${val} 条`);
      this.pageSizesa = val;
      this.listtab();
    },
    handleCurrentChangea(val) {
      console.log(`当前页: ${val}`);
      this.currentPagesa = val;
      this.listtab();
    },
  //申请
  onSubmit(){
    var data = {
      company_id:"",
      sq_type:"",
      hospital_id:"",
      area_id:"",
      total_num:"",
      remark:"",
      product:"",
      company_code:"",
      hospital_code:"",
      area_code:"",
        token: localStorage.getItem("token"),
      };
      postData("approval.sample/sqYangPin", data).then((res) => {
        console.log(res.data);
       this.tableData = res.data.data
      });
  },
     list(){
      var data = {
        page: 1,
        limit: 100,
        token: localStorage.getItem("token"),
      };
      postData("approval.sample/indexlist", data).then((res) => {
        console.log(res.data);
       this.tableData = res.data.data
      });
    },
    handleClick(row) {
      console.log(row);
    },
    handleCheckAllChange(val) {
      const cityOptions = ["上海", "北京", "广州", "深圳"];
      console.log(val);
      this.checkedCities = val ? cityOptions : [];

      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.cities.length;
    },
  },
};
</script>

<style lang="scss" scoped>
.ipt_a {
  width: 240px;
  height: 50px;
  float: left;
}

.ipt_b {
  width: 450px;
  height: 50px;
  float: left;
}
</style>